from pyfbsdk import *
import random
SEARCH_INCLUDE_NAMESPACE = True
SEARCH_ALL_OBJECTS = False
def CreateDatas():
""" This function creates dummy datas with namespace"""
cubenames = ["ns:Cube", "ns:Cube is a troubled cube", "ns:ns1:My Cube of Doom", "ns:this is a ns:ns1:Cube", "Cube ends with be"]
for n in cubenames:
c = FBModelCube("dummy")
c.LongName = n
c.Visible = True
c.Show = True
c.Translation = FBVector3d(random.random()*50, random.random()*50, random.random()*50)
t = FBTexture("texture")
t.LongName = "my text ns:texture of doom"
t = FBTexture("texture")
t.LongName = "my text ns:texture doesn't end with be"
m = FBMaterial("material")
m.LongName = "special ns:material"
def FindWithWildcard(pattern, byName):
""" This function finds an object (not just a model)
with a particular pattern in its name.
"""
cl = FBComponentList()
if byName:
FBFindObjectsByName( pattern, cl, SEARCH_INCLUDE_NAMESPACE, SEARCH_ALL_OBJECTS )
else:
FBFindObjectsByNamespace( pattern, cl )
if len(cl) > 0:
print len(cl), " objects found matching pattern", pattern
for o in cl:
print " ", o.LongName
else:
print "No object found matching pattern", pattern
CreateDatas()
BY_NAME = True
FindWithWildcard( "ns*", BY_NAME )
FindWithWildcard( "*be", BY_NAME )
FindWithWildcard( "*Cube*", BY_NAME )
FindWithWildcard( "*Cube*be*", BY_NAME )
BY_NAMESPACE = False
FindWithWildcard( "ns*", BY_NAMESPACE )
FindWithWildcard( "*ns", BY_NAMESPACE )
FindWithWildcard( "*n*ns*s1", BY_NAMESPACE )